//
//  TitleButton.swift
//  HYYWeibo
//
//  Created by HY-Mac on 16/7/10.
//  Copyright © 2016年 HY-Mac. All rights reserved.
//

import UIKit

class TitleButton: UIButton {
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        //fatalError("init(coder:) has not been implemented")
        super.init(coder: aDecoder)
        setupUI()
    }
    private func setupUI(){
        //addConstraint(NSLayoutConstraint(item: registerBtn, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 35))
        //addConstraint(NSLayoutConstraint(item: titleLabel!, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 80))
        setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        setImage(UIImage(named: "navigationbar_arrow_up"), forState: .Normal)
        setImage(UIImage(named: "navigationbar_arrow_down"), forState: .Selected)
        sizeToFit()
    }
    
    
    override func setTitle(title: String?, forState state: UIControlState) {
        let titleStr = title ?? ""
        super.setTitle(titleStr + "   ", forState: state)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        titleLabel?.frame.origin.x = 0
        imageView?.frame.origin.x = titleLabel!.frame.width

    }
    
}
